<!-- 微信跳转页 -->
<template>
    <div class="div">
        <div class="divTwo">
            <q-linear-progress dark stripe rounded size="20px" :value="progress" color="primary" class="progress" />
            <div>正在加载，请稍等...</div>
        </div>
    </div>
</template>
<script>

export default {
    data() {
        return {
            progress: 0,
            timer: null,
        };
    },

    components: {},

    computed: {},
    watch: {
        $route: {
            immediate: true,
            deep: true,
            handler(val) {
                if (val && val.path == '/wechat') {
                    console.log(val)
                    if (Object.keys(val.query).length != 0) {
                        this.login(val.query)
                    } else {
                        this.$router.push('login')
                    }
                }

            }
        },
    },
    mounted() {
        localStorage.setItem('superRouters_GFYW', JSON.stringify(this.$router.options.routes));
        this.timer = setInterval(() => {
            this.progress++
        }, 200)
    },

    methods: {
        login(item) {
            this.$nextTick(() => {
                this.$store.dispatch('login/weChatloginFun', item).then(res => {
                    if (res.status != 400) {
                        let data = { is_staff: res.is_staff, is_superuser: res.is_superuser }
                        this.$store.dispatch('login/getVisitMenu', data).then(res => {
                            let arr = item.returnurl.split('?')
                            this.$router.push(arr[0])
                        })
                    }
                })
            })
        },
    },
    beforeMount() {
        clearInterval(this.timer)
    }
}

</script>
<style lang='scss' scoped>
.div {
    width: 100%;
    height: 100%;

    .divTwo {
        width: 80%;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        text-align: center;
        font-size: 20px;

        .progress {
            width: 100%;
        }

        div {
            margin-top: 10px;
        }
    }

}
</style>
